home *** CD-ROM | disk | FTP | other *** search
- ;void input_integer(col,row,color,max_len,return_strg);
- ; unsigned short col,row,color,max_len;
- ; char *return_strg;
-
- EXTRN _memory_model:byte
- EXTRN _beep_on:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _input_integer
- _input_integer proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- cmp _memory_model,0 ;code near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb A0 ;jump if near
- les si,dword ptr[bp+12] ;ES:SI pts to return strg
- jmp short A00 ;jump ahead
- A0: mov ax,ds ;move DS to ES
- mov es,ax ;
- mov si,[bp+12] ;ES:SI pts to return strg
- A00: mov byte ptr es:[si],0 ;set NumStrg descriptor
- mov dl,[bp+4] ;column in DL
- dec dl ;count from 0
- mov dh,[bp+6] ;row in DH
- dec dh ;count from 0
- sub bh,bh ;select page 0
- mov bl,[bp+8] ;attribute in BL
- mov al,[bp+10] ;MaxLen to AL
- or al,al ;test for zero length
- jnz A1 ;jump if not zero
- jmp Q1 ;else quit routine
- A1: sub ah,ah ;clear AH
- mov di,ax ;store MaxLen in DI
- sub bp,bp ;current length in BP
- mov ah,2 ;function to set cursor
- int 10h ;set cursor
- B1: sub ah,ah ;func to read keystroke
- int 16h ;wait for keystroke
- or al,al ;test for extended code
- jnz C1 ;jump if not extended
- cmp ah,83 ;is it the delete key?
- jne B1 ;next keystroke if not
- jmp J1 ;else jump to delete code
- C1: cmp al,8 ;is it the backspace?
- jne D1 ;jump ahead if not
- jmp J1 ;else go to delete code
- D1: cmp al,13 ;chk for carriage return
- jne E1 ;jump ahead if not
- jmp O1 ;else go to CR code
- E1: cmp al,'-' ;chk for minus sign
- jne F1 ;jump ahead if not
- or bp,bp ;current str len 0?
- jnz B1 ;new keystroke if not
- inc di ;inc MaxLen counter
- jmp G1 ;go write it
- F1: cmp al,'0' ;below '0' char?
- jb B1 ;get another keystroke
- cmp al,'9' ;above '9' char?
- ja B1 ;get another keystroke
- cmp bp,di ;cmp current/max length
- jb G1 ;jump ahead if not full
- F2: push dx ;keep cursor position
- mov ah,2 ;DOS func to write char
- mov dl,7 ;bell character
- cmp _beep_on,0 ;test whether beep enabled
- je F3 ;jump ahead if not
- int 21h ;beep!
- F3: pop dx ;restore cursor position
- jmp short B1 ;go get another keystroke
- G1: inc bp ;inc current length
- cmp bp,1 ;only 1 char?
- je I1 ;no char shift if so
- push ax ;save new keystroke
- mov cx,bp ;current length to CX
- dec cx ;count from 0
- sub dl,cl ;shift curs to lft char+1
- H1: inc dl ;cursor back 1 to right
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- mov ah,8 ;func reads cursor char
- int 10h ;read the char
- push ax ;save char
- dec dl ;shift cursor 1 col left
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- pop ax ;restore char
- push cx ;keep counter in CX
- mov ah,9 ;function to write char
- mov cx,1 ;number chars to write
- int 10h ;write the char
- pop cx ;restore counter
- inc dl ;cursor right 1 col
- loop H1 ;go shift next
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- pop ax ;restore new keystroke
- I1: mov ah,9 ;function to write char
- mov cx,1 ;number chars to write
- int 10h ;write the char in AL
- mov cl,1 ;increment value
- add es:[si],cl ;inc NumStrg descriptor
- mov es:[bp][si],al ;write char to NumStrg
- jmp B1 ;go get next keystroke
- J1: or bp,bp ;DELETE: none to delete?
- jnz K1 ;jump ahead if not
- jmp F2 ;ignor, next keystroke
- K1: push dx ;save cursor position
- dec bp ;dec current strg len
- push bp ;save current strg len
- or bp,bp ;test for 0 len
- jnz M1 ;if not 0, shift chars
- mov al,'-' ;1 char, test if '-'
- cmp es:[si+1],al ;chk 1st char in string
- jne L1 ;jump ahead if not '-'
- dec di ;else dec MaxLen ctr
- L1: jmp N1 ;skip char shift when 0
- M1: dec dl ;move cursor 1 col left
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- mov ah,8 ;func reads char at curs
- int 10h ;read the char
- push ax ;save the char
- inc dl ;move cursor 1 col right
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- pop ax ;restore the char
- mov ah,9 ;func to write a char
- int 10h ;write the char
- dec dl ;move cursor 1 col left
- dec bp ;dec str len counter
- cmp bp,0 ;finished shifting chars?
- jne M1 ;loop if not
- mov ah,2 ;func to set cursor
- int 10h ;set the cursor
- N1: mov al,' ' ;write space char
- mov ah,9 ;function to write char
- int 10h ;erase leftmost char
- pop bp ;restore current len
- pop dx ;restore cursor position
- mov ah,2 ;func to set cursor
- int 10h ;set cursor
- mov cl,1 ;decrement value
- sub es:[si],cl ;dec ret str descriptor
- jmp b1 ;go get next keystroke
- O1: sub cx,cx ;convert to C string
- mov cl,es:[si] ;get string length
- or cl,cl ;test for zero length
- jz Q1 ;quit if null string
- P1: mov al,es:[si+1] ;get a char
- mov es:[si],al ;shift downward
- inc si ;forward ptr
- loop P1 ;move whole string
- mov byte ptr es:[si],0 ;terminating byte
- Q1: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _input_integer ENDP
- _TEXT ENDS
- END